import my_db_util as db
import pandas as pd
import os

file_path = "D:\\vrdata\\任务列表.csv"
os.remove(file_path)
conn = db.get_conn()
cursor = conn.cursor()
sql = """
			SELECT
			s.simulation_name,
			t.task_name,
			CONCAT(r.task_id,'\t'),
			r.file_name,
			r.package_name,
			r.version 
		FROM
			(
			SELECT
				* 
			FROM
				simulation_resource_upload 
			WHERE
			( task_id, `version` ) IN ( SELECT task_id, max( u.`version` ) `version` FROM simulation_resource_upload u GROUP BY task_id )) r
			INNER JOIN simulation_info s ON s.id = r.simulation_id
			INNER JOIN task_info t ON t.id = r.task_id 
		WHERE
			s.deleted = 0 
			AND t.deleted = 0
	"""
cursor.execute(sql)
results = cursor.fetchall()

df = pd.DataFrame(results)
df.to_csv(file_path, index=False)
# 关闭游标和连接
cursor.close()
conn.close()
